Skip to content

Add golangci-lint configuration#12

Merged
renecannao merged 2 commits intomasterfrom
phase1/task2-golangci-lint
Mar 23, 2026
Merged

Add golangci-lint configuration#12
renecannao merged 2 commits intomasterfrom
phase1/task2-golangci-lint

Conversation

@renecannao
Copy link
Copy Markdown

Summary

  • Add conservative .golangci.yml configuration enabling errcheck, govet, ineffassign, staticcheck, and unused linters
  • Fix invalid regex syntax ((?sg) -> (?s)) in ts/commands.go caught by staticcheck SA1000
  • Fix unnecessary fmt.Errorf(fmt.Sprintf(...)) pattern in ops/downloads.go caught by staticcheck SA1006
  • Remaining lint warnings are style-only (ineffassign on unused initial values, gosimple suggestions) and can be addressed in a follow-up

Closes #2

Test plan

  • Verify golangci-lint run ./... completes without critical errors
  • Verify existing tests still pass (go test ./...)
  • Confirm the regex fix in ts/commands.go doesn't change test behavior (removed invalid g flag that Go regexp never supported)

Copilot AI review requested due to automatic review settings March 23, 2026 18:58
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a baseline golangci-lint configuration and fixes a couple of staticcheck findings, while also updating Go/module metadata and dependencies.

Changes:

  • Add .golangci.yml enabling a limited set of linters.
  • Fix an invalid regexp flag in ts/commands.go and simplify an fmt.Errorf(fmt.Sprintf(...)) pattern in ops/downloads.go.
  • Update go.mod/go.sum (Go version + multiple dependency bumps) and remove a Go build constraint in downloads/tarball_registry.go.

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
.golangci.yml Introduces golangci-lint configuration (enabled linters + issue limits).
ts/commands.go Adjusts regexp to avoid invalid syntax flagged by staticcheck.
ops/downloads.go Simplifies error construction flagged by staticcheck.
go.mod Raises Go version directive and upgrades multiple dependencies.
go.sum Updates checksums consistent with dependency version changes.
downloads/tarball_registry.go Removes go1.16 build tags from the embedded registry source file.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread ts/commands.go Outdated
Comment on lines 63 to 65
reLines := regexp.MustCompile(`(?s)(^.*ERROR.*)`)
errorLines := reLines.FindAll(contents, -1)
ts.Fatalf("ERRORs found in %s (%s)\n", logFile, errorLines)
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regex used to collect lines with "ERROR" still won’t return individual log lines: with (?s)(^.*ERROR.*) and no multiline flag, ^ anchors to the start of the whole file, so FindAll will typically produce a single large match (potentially spanning multiple lines). Consider switching to a multiline pattern (e.g., using (?m) with line anchors) or line-based scanning so you report the specific lines that contain ERROR.

Suggested change
reLines := regexp.MustCompile(`(?s)(^.*ERROR.*)`)
errorLines := reLines.FindAll(contents, -1)
ts.Fatalf("ERRORs found in %s (%s)\n", logFile, errorLines)
reLines := regexp.MustCompile(`(?m)^.*ERROR.*$`)
errorLines := reLines.FindAllString(string(contents), -1)
ts.Fatalf("ERRORs found in %s\n%s\n", logFile, strings.Join(errorLines, "\n"))

Copilot uses AI. Check for mistakes.
Comment thread ts/commands.go Outdated
reLines := regexp.MustCompile(`(?sg)(^.*ERROR.*)`)
reLines := regexp.MustCompile(`(?s)(^.*ERROR.*)`)
errorLines := reLines.FindAll(contents, -1)
ts.Fatalf("ERRORs found in %s (%s)\n", logFile, errorLines)
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

errorLines is a slice of byte-slices ([][]byte), but it’s formatted with %s in ts.Fatalf. This will produce a formatting error (e.g., %!s([][]uint8=...)) instead of the actual lines. Convert/join the matches into a string (or format each line) before passing to %s.

Suggested change
ts.Fatalf("ERRORs found in %s (%s)\n", logFile, errorLines)
var errorLinesStr []string
for _, line := range errorLines {
errorLinesStr = append(errorLinesStr, string(line))
}
ts.Fatalf("ERRORs found in %s (%s)\n", logFile, strings.Join(errorLinesStr, "; "))

Copilot uses AI. Check for mistakes.
Comment thread .golangci.yml
Comment on lines +4 to +10
linters:
enable:
- errcheck
- govet
- ineffassign
- staticcheck
- unused
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This config enables a few linters, but without linters.disable-all: true golangci-lint will also run its default-enabled linters (which can change between golangci-lint versions). If the intent is to run only the listed conservative set, add disable-all: true and keep the explicit enable list.

Copilot uses AI. Check for mistakes.
Comment thread go.mod
module github.com/datacharmer/dbdeployer

go 1.18
go 1.22
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bumping the module go directive from 1.18 to 1.22 is a breaking change in supported toolchains and goes beyond the PR goal of adding lint config / fixing lint bugs. If 1.22 is required, please update the documented build requirements and ensure CI/tooling expectations match; otherwise consider keeping the existing Go version for this PR.

Copilot uses AI. Check for mistakes.
Comment thread go.mod
github.com/rogpeppe/go-internal v1.12.0
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.6
github.com/stretchr/testify v1.9.0
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR upgrades a number of direct dependencies (cobra, mysql driver, testify, x/*, etc.). That’s a much broader behavioral surface-area than “fix critical lint issues only” and makes it harder to attribute regressions to the lint-related changes. Consider reverting the dependency bumps here (or splitting them into a dedicated dependency-upgrade PR with its own testing/validation).

Suggested change
github.com/stretchr/testify v1.9.0
github.com/stretchr/testify v1.8.4

Copilot uses AI. Check for mistakes.
Comment thread ops/downloads.go
if err != nil {
return downloads.TarballDescription{}, fmt.Errorf(fmt.Sprintf("Error getting version %s (%s-%s)[minimal: %v - newest: %v - guess: %v]: %s",
version, flavor, OS, minimal, newest, guessLatest, err))
return downloads.TarballDescription{}, fmt.Errorf("Error getting version %s (%s-%s)[minimal: %v - newest: %v - guess: %v]: %s",
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The returned error string is capitalized ("Error getting version...") and the original error is interpolated with %s, which loses error wrapping. Prefer a lower-case error message and wrap the underlying error (so callers can use errors.Is/As).

Suggested change
return downloads.TarballDescription{}, fmt.Errorf("Error getting version %s (%s-%s)[minimal: %v - newest: %v - guess: %v]: %s",
return downloads.TarballDescription{}, fmt.Errorf("error getting version %s (%s-%s)[minimal: %v - newest: %v - guess: %v]: %w",

Copilot uses AI. Check for mistakes.
@renecannao
Copy link
Copy Markdown
Author

@gemini-code-assist review

@renecannao
Copy link
Copy Markdown
Author

@claude review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces golangci-lint to the project, a great step for improving code quality. It also includes updates to the Go version and dependencies, along with fixes for issues identified by the new linter. The changes are solid. I've added one suggestion in ts/commands.go to improve the error reporting in a test helper, making test failures more informative.

Comment thread ts/commands.go Outdated
hasError := strings.Contains(string(contents), "ERROR")
if neg && hasError {
reLines := regexp.MustCompile(`(?sg)(^.*ERROR.*)`)
reLines := regexp.MustCompile(`(?s)(^.*ERROR.*)`)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While your change correctly fixes the invalid regex flag, the regex (?s)(^.*ERROR.*) will match the entire file content as a single block if an 'ERROR' is present. This can make the test failure output very large and hard to read. To find and report only the specific lines containing 'ERROR', you could use a multi-line regex. This will make the test output more focused and useful.

Note that with this change, the output will be a list of lines containing errors, which is more informative. However, for even better formatting, you might consider converting the resulting byte slices to strings and joining them with newlines in the ts.Fatalf call in a follow-up change.

Suggested change
reLines := regexp.MustCompile(`(?s)(^.*ERROR.*)`)
reLines := regexp.MustCompile(`(?m)^.*ERROR.*$`)

@renecannao
Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 23, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 23, 2026

Warning

Rate limit exceeded

@renecannao has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 14 minutes and 26 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: cddd40da-9824-41c4-bfe5-3fbea3301871

📥 Commits

Reviewing files that changed from the base of the PR and between 60d23c5 and 74e3748.

📒 Files selected for processing (3)
  • .golangci.yml
  • ops/downloads.go
  • ts/commands.go
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch phase1/task2-golangci-lint

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Add a conservative golangci-lint config enabling errcheck, govet,
ineffassign, staticcheck, and unused linters.

Fix two real bugs caught by staticcheck:
- SA1000: invalid regex syntax (?sg) in ts/commands.go (Go doesn't support 'g' flag)
- SA1006: fmt.Errorf wrapping fmt.Sprintf unnecessarily in ops/downloads.go
@renecannao renecannao force-pushed the phase1/task2-golangci-lint branch from 147b025 to 74e3748 Compare March 23, 2026 20:15
@renecannao renecannao merged commit 88f8fda into master Mar 23, 2026
0 of 3 checks passed
@renecannao renecannao deleted the phase1/task2-golangci-lint branch March 23, 2026 20:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add golangci-lint configuration

2 participants